
*- naming glitch when collecting data 
rename enviro20 enviro3


*** if ends with L, then Likert
*** if ends with Lp, also Likert item but in the Likert+ treatment
*** if ends with Lpp1, Likert + version 1, from -5 to 5
*** if ends with Lpp2, Likert + version 2, from -8 to 8
*** if ends with Lpp3, Likert + version 3, used in main text, from -15 to 15 
*** if QV, then QV



local issues AA gun wall paidL gender gay minW abortion deficit enviro

foreach var in `issues' {

gen `var'Lw2 = .
replace `var'Lw2 = -3 if `var'1 == "Oppose" & `var'3 == "A great deal"
replace `var'Lw2 = -2 if `var'1 == "Oppose" & `var'3 == "A little"
replace `var'Lw2 = -1 if `var'1 == "Oppose" & `var'3 == "Moderately"
replace `var'Lw2 = 0 if `var'1 == "Neither favor nor oppose" 
replace `var'Lw2 = 1 if `var'1 == "Favor" & `var'2 == "Moderately"
replace `var'Lw2 = 2 if `var'1 == "Favor" & `var'2 == "A little"
replace `var'Lw2 = 3 if `var'1 == "Favor" &  `var'2 == "A great deal"

}

local issues AA gun wall paidL gender gay minW abortion deficit enviro


foreach var in `issues' {

gen `var'Lpw2 = .
replace `var'Lpw2 = -3 if `var'1plus == "Oppose" & `var'3plus == "A great deal"
replace `var'Lpw2 = -2 if `var'1plus == "Oppose" & `var'3plus == "A little"
replace `var'Lpw2 = -1 if `var'1plus == "Oppose" & `var'3plus == "Moderately"
replace `var'Lpw2 = 0 if `var'1plus == "Neither favor nor oppose"  
replace `var'Lpw2 = 1 if `var'1plus == "Favor" & `var'2plus == "Moderately"
replace `var'Lpw2 = 2 if `var'1plus == "Favor" & `var'2plus == "A little"
replace `var'Lpw2 = 3 if `var'1plus == "Favor" &  `var'2plus == "A great deal"

replace `var'Lpw2 = -3 if `var'1plus2 == "Oppose" & `var'3plus2 == "A great deal"
replace `var'Lpw2 = -2 if `var'1plus2 == "Oppose" & `var'3plus2 == "A little"
replace `var'Lpw2 = -1 if `var'1plus2 == "Oppose" & `var'3plus2 == "Moderately"
replace `var'Lpw2 = 0 if `var'1plus2 == "Neither favor nor oppose"  
replace `var'Lpw2 = 1 if `var'1plus2 == "Favor" & `var'2plus2 == "Moderately"
replace `var'Lpw2 = 2 if `var'1plus2 == "Favor" & `var'2plus2 == "A little"
replace `var'Lpw2 = 3 if `var'1plus2 == "Favor" &  `var'2plus2 == "A great deal"


}




local issues AA gun wall paidL gender gay minW abortion deficit enviro


foreach var in `issues' {

gen `var'bi = 0 if `var'1plus == "Neither favor nor oppose" 
replace `var'bi = 0 if `var'1plus2 == "Neither favor nor oppose" 
replace `var'bi = -1 if `var'1plus == "Oppose"
replace `var'bi = -1 if `var'1plus2 == "Oppose"
replace `var'bi = 1 if `var'1plus == "Favor"
replace `var'bi = 1 if `var'1plus2 == "Favor"

}


rename minW3plus0 minW4plus


local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {

gen R`var'4plus = 1 if `var'4plus == "Not important at all"
replace R`var'4plus = 2 if `var'4plus == "Not too important"
replace R`var'4plus = 3 if `var'4plus == "Somewhat important"
replace R`var'4plus = 4 if `var'4plus == "Very important"
replace R`var'4plus = 5 if `var'4plus == "Extremely important"


gen R`var'4plus2 = 1 if `var'4plus2 == "Not important at all"
replace R`var'4plus2 = 2 if `var'4plus2 == "Not too important"
replace R`var'4plus2 = 3 if `var'4plus2 == "Somewhat important"
replace R`var'4plus2 = 4 if `var'4plus2 == "Very important"
replace R`var'4plus2 = 5 if `var'4plus2 == "Extremely important"

}



local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {

gen `var'Lpp1w2 = . 
replace `var'Lpp1w2 = `var'bi * (R`var'4plus)  
replace `var'Lpp1w2 = `var'bi * (R`var'4plus2)  if `var'Lpp1w2 == .
}



local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {

gen `var'Lpp2w2 = . 
replace `var'Lpp2w2 =`var'bi * (abs(`var'Lpw2) + (R`var'4plus))
replace `var'Lpp2w2 =`var'bi * (abs(`var'Lpw2) + (R`var'4plus2)) if `var'Lpp2w2 == .
replace `var'Lpp2w2 = 0  if `var'Lpp2w2 == . & `var'bi == 0
}



local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {

gen `var'Lpp3w2 = . 
replace `var'Lpp3w2 =`var'bi * (abs(`var'Lpw2) * (R`var'4plus))
replace `var'Lpp3w2 =`var'bi * (abs(`var'Lpw2) * (R`var'4plus2)) if `var'Lpp3w2 == .
replace `var'Lpp3w2 = 0  if `var'Lpp3w2 == . & `var'bi == 0
}




rename QV1 QVgayw2
rename QV2 QVgunw2
rename QV3 QVwallw2
rename QV4 QVpaidLw2
rename QV5 QVAAw2
rename QV6 QVgenderw2
rename QV7 QVminWw2
rename QV8 QVabortionw2
rename QV9 QVdeficitw2
rename QV10 QVenvirow2


local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {
destring QV`var'w2, replace
}




local issues AA gun wall paidL gender gay minW abortion deficit  enviro
foreach var in `issues' {


gen votes_`var'w2 = .
replace votes_`var'w2 = 0 if `var'Lw2 == 0 | `var'Lpp1w2 == 0 | QV`var'w2 == 0
replace votes_`var'w2 = 1 if `var'Lw2 == 1 | `var'Lpp1w2 == 1 | QV`var'w2 == 1
replace votes_`var'w2 = 2 if `var'Lw2 == 2 | `var'Lpp1w2 == 2 |  QV`var'w2 == 2
replace votes_`var'w2 = 3 if `var'Lw2 == 3 | `var'Lpp1w2 == 3 | QV`var'w2 == 3
replace votes_`var'w2 = 4 if  `var'Lpp1w2 == 4 | QV`var'w2 == 4
replace votes_`var'w2 = 5 if  `var'Lpp1w2 == 5 | QV`var'w2 == 5
replace votes_`var'w2 = QV`var' if QV`var' < . & votes_`var'w2 == . & method == 3



replace votes_`var'w2 = -1 if `var'Lw2 == -1 | `var'Lpp1w2 == -1 | QV`var'w2 == -1
replace votes_`var'w2 = -2 if `var'Lw2 == -2 | `var'Lpp1w2 == -2 |  QV`var'w2 == -2
replace votes_`var'w2 = -3 if `var'Lw2 == -3 | `var'Lpp1w2 == -3 | QV`var'w2 == -3
replace votes_`var'w2 = -4 if  `var'Lpp1w2 == -4 | QV`var'w2 == -4
replace votes_`var'w2 = -5 if  `var'Lpp1w2 == -5 | QV`var'w2 == -5
replace votes_`var'w2 = (-1) * QV`var' if QV`var' < . & votes_`var'w2 == . & method == 3 


}

local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {
recode votes_`var'w2 ( 10 9 8  = 7) ( -10 -9 -8  = -7) if method == 3
}


*-------------------------------
*--- Additional coding of variables of interest -- Lpp2 and Lpp3



local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {
gen votes_`var'w2LPP2 = votes_`var'w2
replace votes_`var'w2LPP2 = `var'Lpp2w2 if `var'Lpp2w2 < .
}



local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {
gen votes_`var'w2LPP3 = votes_`var'w2
replace votes_`var'w2LPP3 = `var'Lpp3w2 if `var'Lpp3w2 < .
}



local issues wall abortion deficit 
foreach var in `issues' {
gen votes_`var'_inw2= (-1) * votes_`var'w2
gen votes_`var'_inw2LPP2 = (-1) * votes_`var'w2LPP2
gen votes_`var'_inw2LPP3 = (-1) * votes_`var'w2LPP3
}



******* issu important item for Table E8

local var gun wall gender paidL  minW abortion
foreach var in `var' {
gen `var'_IP = (6 - R`var'4plus)
replace `var'_IP = R`var'4plus2 if `var'_IP == .
}





**----------------------------
*** NORMALIZE



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen votes_`var'w2N = (votes_`var'w2 - (-3)) / (3 - (-3)) if method == 1
replace votes_`var'w2N = (votes_`var'w2 - (-5)) / (5 - (-5)) if method == 2
sum votes_`var'w2 if method == 3 
egen minQV`var' = min(votes_`var'w2) if method == 3
egen maxQV`var' = max(votes_`var'w2) if method == 3
replace votes_`var'w2N = (votes_`var'w2 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'
}




local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
capture drop abs_votes_`var'w2 abs_votes_`var'w2N
gen abs_votes_`var'w2 = abs(votes_`var'w2) 
gen abs_votes_`var'w2N = (abs_votes_`var'w2 - (0)) / (3 - (0)) if method == 1
replace abs_votes_`var'w2N = (abs_votes_`var'w2 - (0)) / (5 - (0)) if method == 2
egen minQV`var' = min(abs_votes_`var'w2) if method == 3
egen maxQV`var' = max(abs_votes_`var'w2) if method == 3
replace abs_votes_`var'w2N = (abs_votes_`var'w2 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'
}




*** Normalize [0-1] -- LPP2
local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen votes_`var'w2LPP2N = (votes_`var'w2LPP2 - (-3)) / (3 - (-3)) if method == 1
replace votes_`var'w2LPP2N = (votes_`var'w2LPP2 - (-8)) / (8 - (-8)) if method == 2
egen minQV`var' = min(votes_`var'w2LPP2) if method == 3
egen maxQV`var' = max(votes_`var'w2LPP2) if method == 3
replace votes_`var'w2LPP2N = (votes_`var'w2LPP2 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'
}



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen abs_votes_`var'w2LPP2 = abs(votes_`var'w2LPP2) 
gen abs_votes_`var'w2LPP2N = (abs_votes_`var'w2LPP2 - (0)) / (3 - (0)) if method == 1
replace abs_votes_`var'w2LPP2N = (abs_votes_`var'w2LPP2 - (0)) / (8 - (0)) if method == 2
egen minQV`var' = min(abs_votes_`var'w2LPP2) if method == 3
egen maxQV`var' = max(abs_votes_`var'w2LPP2) if method == 3
replace abs_votes_`var'w2LPP2N = (abs_votes_`var'w2LPP2 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'

}


*** Normalize [0-1] -- LPP3
local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen votes_`var'w2LPP3N = (votes_`var'w2LPP3 - (-3)) / (3 - (-3)) if method == 1
replace votes_`var'w2LPP3N = (votes_`var'w2LPP3 - (-15)) / (15 - (-15)) if method == 2
egen minQV`var' = min(votes_`var'w2LPP3) if method == 3
egen maxQV`var' = max(votes_`var'w2LPP3) if method == 3
replace votes_`var'w2LPP3N = (votes_`var'w2LPP3 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'
}



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen abs_votes_`var'w2LPP3 = abs(votes_`var'w2LPP3) 
gen abs_votes_`var'w2LPP3N = (abs_votes_`var'w2LPP3 - (0)) / (3 - (0)) if method == 1
replace abs_votes_`var'w2LPP3N = (abs_votes_`var'w2LPP3 - (0)) / (15 - (0)) if method == 2
egen minQV`var' = min(abs_votes_`var'w2LPP3) if method == 3
egen maxQV`var' = max(abs_votes_`var'w2LPP3) if method == 3
replace abs_votes_`var'w2LPP3N = (abs_votes_`var'w2LPP3 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'

}



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
	corr votes_`var'w2N votes_`var'w2LPP2N votes_`var'w2LPP3N if method == 1
	corr votes_`var'w2N votes_`var'w2LPP2N votes_`var'w2LPP3N if method == 2
	corr votes_`var'w2N votes_`var'w2LPP2N votes_`var'w2LPP3N if method == 3
}







***************
*** Wave 2 Outcomes

gen DG_ind = .
replace DG_ind = donW2ind if donW2indb =="Yes, take me to the next page"
replace DG_ind = donW2inc if donW2indb =="No, I would like to modify my answer"
replace DG_ind = 0 if DG_ind == . & Q759 =="Yes, take me to the next page"
replace DG_ind = Q760 if DG_ind == . & Q759 =="No, I would like to modify my answer"


gen DG_rep = .
replace DG_rep = donW2rep if donW2repb =="Yes, take me to the next page"
replace DG_rep = donW2repc if donW2repb =="No, I would like to modify my answer"
replace DG_rep = 0 if DG_rep == . & Q761 =="Yes, take me to the next page"
replace DG_rep = Q762 if DG_rep == . & Q761 =="No, I would like to modify my answer"


rename donW2demb0 donW2demc

gen DG_dem = .
replace DG_dem = donW2dem if donW2demb =="Yes, take me to the next page"
replace DG_dem = donW2demc if donW2demb =="No, I would like to modify my answer"
replace DG_dem = 0 if DG_dem == . & Q763 == "Yes, take me to the next page"
replace DG_dem = Q764 if DG_dem == . & Q763 =="No, I would like to modify my answer"


*** punish *** how much give second time around 

gen DG_punish = .
replace DG_punish = donW2c if updatingW2c == "Yes, take me to the next page"
replace DG_punish = DG_ind if updatingW2c != "Yes, take me to the next page" & updatingW2c != "" 
replace DG_punish = donW2cbis if DG_punish == . & updatingW2cbis == "Yes, take me to the next page"
replace DG_punish = DG_ind if DG_punish == . & updatingW2cbis != "Yes, take me to the next page"  & updatingW2cbis != "" 
replace DG_punish = DG_ind if DG_punish == . 


*** Outcome

gen punish_Fa = DG_ind - DG_punish

*** extensive binary :punished

recode punish_Fa (-100/0 = 0) (1/100=1), gen(punished) 
recode punish_Fa (-100/-1 = 1) (0/100=0), gen(rewarded) 


** as a proportion

gen proportion = 0 if punished == 0  & rewarded == 0
replace proportion = punish_Fa / DG_ind if DG_ind ! = 0 & proportion != 0 



*** letter 

gen intent_contact = . 
replace intent_contact = 1 if write_pick == "No, take me to the end of the survey"
replace intent_contact = 2 if write_pick == "Yes, help me find the contact pages"
replace intent_contact = 9999 if bill_pick1 == "No"

**--------- DV 1: wrote? if so, wrote about what
gen wrote = . 
replace wrote = 0 if bill_pick1 == "No"
replace wrote = 1 if bill_pick1 == "Yes" & bill_pick2 == "Raise the Wage Act"
replace wrote = - 1 if bill_pick1 == "Yes" & bill_pick2 == "No Taxpayer Funding for Abortion and Abortion Insurance Full Disclosure Act"

tab wrote 

gen W_minW = wrote == 1
replace W_minW  = 0 if wrote < 1
replace W_minW  = . if wrote == .

gen W_abortion_in = wrote == -1
replace W_abortion_in  = 0 if wrote > -1
replace W_abortion_in  = . if wrote == .



***** writing

gen writing = strlen(Q175)
replace writing = . if W_minW == . & W_abortion_in == .

gen writing_abortion = writing
replace writing_abortion = 0 if W_minW == 1

gen writing_minW = writing
replace writing_minW = 0 if W_abortion == 1


merge 1:1 id_w2  using "$pathdata/text.dta"

drop if _merge == 2 
drop _merge 


replace writing_new = . if W_minW == . & W_abortion_in == .

gen writing_abortionN = writing_new
replace writing_abortionN = 0 if W_minW == 1
replace writing_abortionN = writing_abortion if writing_abortionN == .
replace writing_abortionN = writing_abortion if writing_abortionN < writing_abortion

gen writing_minWN = writing_new
replace writing_minWN = 0 if W_abortion == 1
replace writing_minWN = writing_minW if writing_minWN == .
replace writing_minWN = writing_minW if writing_minWN < writing_minW


replace writing_abortionN = 733 if writing_abortionN >= 733 & writing_abortionN < .



local issues punish_Fa writing_abortion writing_minW writing_abortionN writing_minWN proportion
foreach var in `issues' { 
sum `var', de
gen `var'ST = (`var' - r(mean)) / (r(sd) * 1)
}














